package com.heima.wemedia.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.mapper.WmSensitiveMapper;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 陈辉
 * @data 2023 15:50
 */
@Service
public class WmSensitiveServiceImpl extends ServiceImpl<WmSensitiveMapper, WmSensitive> implements WmSensitiveService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<WmSensitive> findAllSensitive() {
        //1. 先看看redis里有没有
        List<WmSensitive> sensitive = (List<WmSensitive>) redisTemplate.opsForValue().get("sensitive");
        if (sensitive != null)return sensitive;

        //查询数据库
        sensitive = this.list();

        //存入redis
        redisTemplate.opsForValue().set("sensitive",sensitive);
        return sensitive;
    }
}
